home *** CD-ROM | disk | FTP | other *** search
- //
- // MFC_PGM.CPP [edit EMAIL.H before compiling]
- //
- // MFC_PGM is intended as a simple example of the use of
- // the Microsoft Foundation Class (MFC) library with the
- // SMTP/POP3 Email Engine for C/C++ (SEE4C).
- //
- // This example emails a simple message.
- //
- // Edit EMAIL.H and SEND_TO, SUBJECT, and MESSAGE (line 97 below)
- // before compiling.
- //
-
- #include "stdafx.h"
- #include "resource.h"
-
- #include "see.h"
- #include "mfc_pgm.h"
-
- static CWnd * MainWndPtr;
-
- // CMainWindow: constructor
-
- CMainWindow::CMainWindow()
- {int Row;
- CString s = "WSC Test";
- LoadAccelTable( "MainAccelTable" );
- Create( NULL, "MFC Example Program",
- WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu" );
- for(Row=0;Row<NROWS;Row++) Buffer[Row].Empty;
- TheRow = 0;
- }
-
- // Display character on screen
-
- void CMainWindow::DisplayChar(int nChar)
- {int Row;
- // process the character
- if(nChar==10) return;
- if(nChar==13)
- {if(TheRow<NROWS-1) TheRow++;
- else
- {// scroll page (TheRow==NROWS-1)
- for(Row=0;Row<=NROWS-2;Row++) Buffer[Row] = Buffer[Row+1];
- Buffer[NROWS-1].Empty();
- TheRow = NROWS-1;
- }
- }
- else
- {// stuff character into display buffer
- Buffer[TheRow] += (char)nChar;
- }
- }
-
- // Display string on screen
-
- void CMainWindow::DisplayLine(CString Text)
- {
- Buffer[TheRow] += Text;
- DisplayChar(13);
- Invalidate(TRUE);
- }
-
- // CMainWindow message map
-
- BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
- //{{AFX_MSG_MAP( CMainWindow )
- ON_WM_PAINT()
- ON_COMMAND(ID_EXIT, PgmExit)
- ON_COMMAND(ID_SEND, PgmSend)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- CTheApp NEAR theApp;
-
- // PgmExit: Exits application
-
- void CMainWindow::PgmExit(void)
- {
- PostQuitMessage(0);
- }
-
- // display error message
-
- void CMainWindow::ShowError(int Code)
- {static char Buffer[65];
- static char Temp[90];
- seeErrorText(Code,(LPSTR)Buffer,65);
- wsprintf((LPSTR)Temp,"SEE Error %d: %s\n", Code, (LPSTR)Buffer);
- DisplayLine((LPSTR)Temp);
- }
-
- // PgmSend : Send email
- void CMainWindow::PgmSend(void)
- {int Code;
-
- #include "email.h"
- #define SEND_TO "<msc@traveller.com>"
- #define SUBJECT "Email from MFC_PGM"
- #define MESSAGE "This is a test.\r\n\r\n--Mike"
-
- // connect to SMTP server
- DisplayLine("Connecting...");
- Code = seeSmtpConnect(
- (LPSTR)SMTP_HOST_NAME, // SMTP server
- (LPSTR)YOUR_EMAIL_ADDR, // return email address
- (LPSTR)NULL); // Reply-To header
- if(Code<0)
- {ShowError(Code);
- return;
- }
- // send email
- DisplayLine("Sending mail...");
- Code = seeSendEmail(
- (LPSTR)SEND_TO, // To list
- (LPSTR)NULL, // CC list
- (LPSTR)NULL, // BCC list
- (LPSTR)SUBJECT, // subject
- (LPSTR)MESSAGE, // message text
- (LPSTR)NULL); // MIME attachment
- if(Code<0)
- {ShowError(Code);
- return;
- }
- DisplayLine("Closing...");
- Code = seeClose();
- Invalidate(TRUE);
- }
-
- // OnPaint:
-
- void CMainWindow::OnPaint()
- {int Row;
- CPaintDC dc( this );
- CRect rect;
- GetClientRect( rect );
- dc.SetTextAlign( TA_BASELINE | TA_LEFT );
- dc.SetTextColor( ::GetSysColor( COLOR_WINDOWTEXT ) );
- dc.SetBkMode(TRANSPARENT);
- dc.SelectStockObject(ANSI_FIXED_FONT);
- for(Row=0;Row<=TheRow;Row++)
- {// display the row
- dc.TextOut( 4, 16+(Row<<4), Buffer[Row], Buffer[Row].GetLength() );
- }
- }
-
- // InitInstance:
-
- BOOL CTheApp::InitInstance()
- {SetDialogBkColor(); //hook gray dialogs
- m_pMainWnd = new CMainWindow();
- m_pMainWnd->ShowWindow( m_nCmdShow );
- m_pMainWnd->UpdateWindow();
- MainWndPtr = m_pMainWnd;
- return TRUE;
- }
-